package com.company.test29;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by v on 16-11-25.
 */
public class TestLock implements Runnable{
    private Lock lock=new ReentrantLock();
    private int balance=0;

    @Override
    public void run() {
        addBalance();
        System.out.println("out");
    }

    private void addBalance(){
        lock.lock();
        balance++;
        try{
            Thread.sleep(5);
        }catch (InterruptedException ex){

        }
        //lock.unlock();
    }

    public static void main(String[] args) {
        ExecutorService executor= Executors.newCachedThreadPool();
        for(int i=0;i<10;i++){
            executor.execute(new TestLock());
        }

        executor.shutdown();
    }
}
